from django.shortcuts import render, reverse, redirect
from django.http import HttpResponse
from django.utils import timezone

from django.urls import resolve


def mydate(request, year, month, day):
    args = ['2025', '09', '04']
    result = resolve(reverse('home:mydate', args=args))
    print(f'func:{result.func}')
    print(f'args:{result.args}')
    print(f'kwargs:{result.kwargs}')
    print(f'url_name:{result.url_name}')
    print(f'namespace:{result.namespace}')
    print(f'namespaces:{result.namespaces}')
    print(f'view_name:{result.view_name}')
    print(f'app_name:{result.app_name}')
    print(f'app_names:{result.app_names}')
    return HttpResponse(f'{str(year)}/{str(month)}/{str(day)}')


def index(request):
    kwargs = {'year': 2021, 'month': 9, 'day': 4}
    args = ['2025', '09', '04']
    # 使用reverse 生成路由地址
    print(reverse('home:mydate', args=args))
    print(reverse('home:mydate', kwargs=kwargs))

    # return render(request, 'url_demo.html')
    # return HttpResponse(reverse('home:mydate', args=args))
    return redirect(reverse('index:index'))


def now_time(request):
    current_time = timezone.now()  # 获取当前时区的时间
    print(current_time)
    return HttpResponse(current_time)
